package morefun.demo

import morefun.demo.utils.SecondSortKey
import org.apache.spark.{SparkConf, SparkContext}

object SecondSort {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("SecondSort").setMaster("local")
    val sc = new SparkContext(conf)

    val scoresList = Array(Tuple2(1, 1),Tuple2(2,4),Tuple2(3,1),Tuple2(1,2),Tuple2(2,2),Tuple2(2,2))
    val scores = sc.parallelize(scoresList)
    // 自己实现一个可以根据第二个参数进行排序的 key
    val pairs = scores.map(score => (new SecondSortKey(score._1, score._2), score))
    val secondSort = pairs.sortByKey()

    secondSort.foreach(println(_))
  }
}
